package cn.anosi.repository.auth;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import cn.anosi.entity.auth.RolePermission;

public interface RolePermissionRepository extends JpaRepository<RolePermission, Integer>,JpaSpecificationExecutor<RolePermission>{
	
	/**
	 * 根据角色id，查询关联的权限id
	 * @param id
	 * @return
	 */
	@Query(value = "select t.permission_id from role_permission t where role_id = ?1", nativeQuery=true)
	List<Integer> getPermissionIds(Integer id);

	@Modifying
	@Query(value = "delete FROM role_permission where role_id = ?", nativeQuery=true)
	int deletePermissionByRoleId(Integer roleId);

	@Modifying
	@Query(value = "insert into role_permission (role_id, permission_id) values (?1, ?2)",nativeQuery=true)
	int associate(Integer roleId, Integer id);
}
